package com.common.config;

import net.sf.ehcache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.cache.support.CompositeCacheManager;
import org.springframework.cache.support.NoOpCacheManager;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.cache.RedisCacheManager;

/**
 * @classDescription:
 * @author:xiayingjie
 * @createTime:16/8/16
 */
@Configuration
@EnableCaching
public class CacheConfig {

    //使用 concurrentMap实现
//    @Bean
//    public CacheManager cacheManager(){
//        return new ConcurrentMapCacheManager();
//        new SimpleCacheManager();
//        new NoOpCacheManager();
//        new SimpleCacheManager();
//        new CompositeCacheManager();
//        new EhCacheCacheManager();
//        new RedisCacheManager();
//        new RedisCacheManager();
//    }

    //ehcache实现 也可以取名叫
    @Bean
    public EhCacheCacheManager cacheManager(CacheManager cm){
        return new EhCacheCacheManager(cm);
    }

    //创建echcache的CacheManager实例，因为是工厂(实现了FacotoryBean)
    @Bean
    public EhCacheManagerFactoryBean ehcache(){
        EhCacheManagerFactoryBean factoryBean=new EhCacheManagerFactoryBean();
        factoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
        return factoryBean;
    }





}
